package com.hc.conferencecheck.utils;

import com.hc.conferencecheck.service.impl.ConventionerServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * 用于存储cookie的工具类
 */
public class CookieUtils {
    public static final Logger logger = LoggerFactory.getLogger(CookieUtils.class);

    /**
     * 用于存储用户信息的cookie工具类
     *
     * @param response
     * @param json
     */
    public static void addCookie(HttpServletResponse response, String json) {
//        String encodeUser = null;
//        try {
//            encodeUser = URLEncoder.encode(json, "UTF-8");
//        } catch (UnsupportedEncodingException e) {
//            logger.error("用户信息加密失败");
//            e.printStackTrace();
//        }
        Cookie cookie = new Cookie("user", json);
        cookie.setPath("/");
        //设置cookie的有效期为20分钟
        cookie.setMaxAge(20 * 60);
        response.addCookie(cookie);
    }
}
